package com.guigu.qingcheng.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.guigu.qingcheng.mapper.TbOrderLogMapper;
import com.guigu.qingcheng.pojo.TbOrderLog;
import com.guigu.qingcheng.service.TbOrderLogService;
import com.guigu.qingcheng.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;


/**
*
* @author Jiang
* @date 2020/07/31
*/
@Service
public class TbOrderLogServiceImpl implements TbOrderLogService {
    @Autowired(required = false)
    private TbOrderLogMapper tbOrderLogMapper;



    @Override
    public List<TbOrderLog> queryAll() {
        List<TbOrderLog> tbOrderLog = tbOrderLogMapper.selectAll();
            return tbOrderLog;
    }

    @Override
    public PageUtil<TbOrderLog> findListAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<TbOrderLog> pages = (Page<TbOrderLog>) tbOrderLogMapper.selectAll();
        PageUtil<TbOrderLog> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
    }


    @Override
    public PageUtil<TbOrderLog> pageQueryByAll(Integer pageNum, Integer pageSize, TbOrderLog tbOrderLog) {

        Example example=new Example(TbOrderLog.class);
        Example.Criteria criteria = example.createCriteria();
        // TODO 待实现 重新实现判断参数

        //if(!StringUtils.isEmpty(brand.getId())){
        //    criteria.andEqualTo("id",brand.getId());
        //}
//        if(!StringUtils.isEmpty(brand.getName())){
//           criteria.andLike("name","%"+brand.getName()+"%");
//        }
        PageHelper.startPage(pageNum,pageSize);
        Page<TbOrderLog> pages = (Page<TbOrderLog>) tbOrderLogMapper.selectByExample(example);
        PageUtil<TbOrderLog> pageUtil=new PageUtil<>();
        pageUtil.setRows(pages.getResult());
        pageUtil.setTotal(pages.getTotal());
        return pageUtil;
     }


    @Override
    public boolean saveTbOrderLog(TbOrderLog tbOrderLog) {
        int insert = tbOrderLogMapper.insert(tbOrderLog);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateTbOrderLog(TbOrderLog tbOrderLog) {
        int i = tbOrderLogMapper.updateByPrimaryKeySelective(tbOrderLog);
        if(i>0){
            return true;
        }
        return false;
    }


    @Override
    public boolean deleteById(Integer id) {
        int i = tbOrderLogMapper.deleteByPrimaryKey(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public TbOrderLog findById(Integer id) {
        TbOrderLog tbOrderLog = tbOrderLogMapper.selectByPrimaryKey(id);
        return tbOrderLog;
    }

    @Override
    public List<TbOrderLog> orderByLog(String id) {
        Example example=new Example(TbOrderLog.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("orderId",id);

        List<TbOrderLog> orderLogs = tbOrderLogMapper.selectByExample(example);
        return orderLogs;
    }
}
